<template>
  <div id="app">
    <el-container>
      <el-header style="background-color: #4c535a;">
        <img src="@/assets/logo.png" class="logoStyle" />
        <span class="titlesStyle">权限管理系统</span>
        <div style="float: right;margin-top: 17px;">


          <el-dropdown @command="handleCommand">
            <span class="el-dropdown-link" style="color: red;padding-top: 10px;">
              {{ userInfo.name }}<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="userCenter">个人中心</el-dropdown-item>
              <el-dropdown-item command="loginOut">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>

    </el-container>

    <el-container>
      <el-aside style="background-color: #545c64; width: 200px;min-height: 100vh;overflow: hidden;">
        <el-menu :default-active="$route.path" router class="el-menu-vertical-demo" background-color="#545c64"
          text-color="#fff" active-text-color="#ffd04b">
          <el-menu-item index="/">
            <i class="el-icon-menu"></i>
            <span slot="title">系统首页</span>
          </el-menu-item>
          <el-submenu index="2" v-if="userInfo.role==='ROLE_ADMIN'">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>用户管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/admin">管理员信息</el-menu-item>
              <el-menu-item index="2-2">用户信息</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>信息管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/books">图书信息</el-menu-item>
              <el-menu-item index="/type">图书分类</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view />
      </el-main>
    </el-container>

  </div>
</template>
<script>
export default {
  name: 'LayOutView',
  data(){
    return{
      userInfo:{

      }
    }
  },
  methods:{
    //退出登录触发该事件
    handleCommand(command){
      if(command==='loginOut'){
        localStorage.removeItem("user")
        this.$router.push("/login")
      }
      
    }
  },
  created(){
    this.userInfo=JSON.parse( localStorage.getItem("user"));
    console.log("用户名称",this.userInfo.name);
  }
}
</script>
<style >
* {
  padding: 0px;
  margin: 0px;
}

/* logo样式 */
.logoStyle {
  width: 40px;
  position: relative;
  top: 10px;
  margin-left: 10px;
}


.titlesStyle {
  color: #fff;
  font-size: 20px;
  margin-left: 15px;
}

.el-menu {
  border-right: none !important;
}
</style>
